{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Number of Strings That Appear as Substrings in Word"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: numOfStrings"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #作为子字符串出现在单词中的字符串数目"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个字符串数组 <code>patterns</code> 和一个字符串 <code>word</code> ，统计 <code>patterns</code> 中有多少个字符串是 <code>word</code> 的子字符串。返回字符串数目。</p>\n",
    "\n",
    "<p><strong>子字符串</strong> 是字符串中的一个连续字符序列。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>patterns = [\"a\",\"abc\",\"bc\",\"d\"], word = \"abc\"\n",
    "<strong>输出：</strong>3\n",
    "<strong>解释：</strong>\n",
    "- \"a\" 是 \"<em><strong>a</strong></em>bc\" 的子字符串。\n",
    "- \"abc\" 是 \"<em><strong>abc</strong></em>\" 的子字符串。\n",
    "- \"bc\" 是 \"a<em><strong>bc</strong></em>\" 的子字符串。\n",
    "- \"d\" 不是 \"abc\" 的子字符串。\n",
    "patterns 中有 3 个字符串作为子字符串出现在 word 中。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>patterns = [\"a\",\"b\",\"c\"], word = \"aaaaabbbbb\"\n",
    "<strong>输出：</strong>2\n",
    "<strong>解释：</strong>\n",
    "- \"a\" 是 \"a<em><strong>a</strong></em>aaabbbbb\" 的子字符串。\n",
    "- \"b\" 是 \"aaaaabbbb<em><strong>b</strong></em>\" 的子字符串。\n",
    "- \"c\" 不是 \"aaaaabbbbb\" 的字符串。\n",
    "patterns 中有 2 个字符串作为子字符串出现在 word 中。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>patterns = [\"a\",\"a\",\"a\"], word = \"ab\"\n",
    "<strong>输出：</strong>3\n",
    "<strong>解释：</strong>patterns 中的每个字符串都作为子字符串出现在 word \"<em><strong>a</strong></em>b\" 中。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= patterns.length &lt;= 100</code></li>\n",
    "\t<li><code>1 &lt;= patterns[i].length &lt;= 100</code></li>\n",
    "\t<li><code>1 &lt;= word.length &lt;= 100</code></li>\n",
    "\t<li><code>patterns[i]</code> 和 <code>word</code> 由小写英文字母组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [number-of-strings-that-appear-as-substrings-in-word](https://leetcode.cn/problems/number-of-strings-that-appear-as-substrings-in-word/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [number-of-strings-that-appear-as-substrings-in-word](https://leetcode.cn/problems/number-of-strings-that-appear-as-substrings-in-word/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[\"a\",\"abc\",\"bc\",\"d\"]\\n\"abc\"', '[\"a\",\"b\",\"c\"]\\n\"aaaaabbbbb\"', '[\"a\",\"a\",\"a\"]\\n\"ab\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        num = 0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                num +=1\n",
    "        return num\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        res = 0\n",
    "        for pattern in patterns:\n",
    "            if pattern in word:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        counter = 0\n",
    "        for pattern in patterns:\n",
    "            if pattern in word:\n",
    "                counter += 1\n",
    "\n",
    "        return counter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        sums=0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                sums+=1\n",
    "        return sums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        sum0=0\n",
    "        for i in range(len(patterns)):\n",
    "                if patterns[i] in word:\n",
    "                    sum0+=1\n",
    "        return sum0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        res = 0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                res += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        ans = 0\n",
    "        for w in patterns:\n",
    "            if w in word:ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        ans = 0 \n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                ans +=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        ans = 0\n",
    "        for sub_string in patterns:\n",
    "            if sub_string in word:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        cnt = 0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        s = 0 \n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                s += 1\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        num = 0\n",
    "        for i in patterns:\n",
    "            if word.find(i)!=-1:\n",
    "                num+=1\n",
    "        return num        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        cnt = 0\n",
    "        for pa in patterns:\n",
    "            if word.find(pa) != -1:\n",
    "                cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        res = 0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        v=0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                v+=1\n",
    "        return v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        # num = 0\n",
    "        # for pattern in patterns:\n",
    "        #     if pattern in word:\n",
    "        #         num += 1\n",
    "        # return num\n",
    "\n",
    "        return sum([1 if pattern in word else 0 for pattern in patterns])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return sum([1 if word.find(pattern) != -1 else 0 for pattern in patterns])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return len(list(filter(lambda x: x in word, patterns)))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        nums = 0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                nums += 1\n",
    "        return nums\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        num = 0\n",
    "        for pattern in patterns:\n",
    "            if pattern in word:\n",
    "                num += 1\n",
    "        return num\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        ans = 0\n",
    "        for p in patterns:\n",
    "            if p in word:\n",
    "                ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        ans=0\n",
    "        for s in patterns:\n",
    "            if s in word:\n",
    "                ans+=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        count = 0\n",
    "        for i in patterns:\n",
    "            if word.count(i) > 0:\n",
    "                count += 1\n",
    "        return count\n",
    "\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        res = 0\n",
    "        for pattern in patterns:\n",
    "            if pattern in word:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        count=0\n",
    "        for pattern in patterns:\n",
    "            if pattern in word:\n",
    "                count+=1\n",
    "        return count\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return sum(pattern in word  for pattern in patterns)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        count = 0\n",
    "        for pattern in patterns:\n",
    "            if pattern in word:\n",
    "                count = count + 1\n",
    "\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        c = 0\n",
    "        for i in patterns:\n",
    "            if i in word != True:\n",
    "                c += 1\n",
    "        return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        count = 0\n",
    "        for pattern in patterns:\n",
    "            if pattern in word:\n",
    "                count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        ans = 0\n",
    "        for x in patterns:\n",
    "            if x in word:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return sum(pattern in word  for pattern in patterns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        count=0\n",
    "        for i in patterns:\n",
    "            #print(i,word,word.find(i))\n",
    "            if word.find(i)>=0:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return sum(1 for i in patterns if i in word)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return sum(x in word for x in patterns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        ans = 0\n",
    "        for p in patterns:\n",
    "            if p in word:\n",
    "                ans += 1\n",
    "        \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\r\n",
    "        ans = 0\r\n",
    "        for i in patterns:\r\n",
    "            if i in word:\r\n",
    "                ans += 1\r\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        n = len(patterns)\n",
    "        count = 0\n",
    "        for i in range(n):\n",
    "            if word.count(patterns[i]) > 0:\n",
    "                count += 1\n",
    "        return count\n",
    "\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return sum(i in word for i in patterns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return len(list(filter(lambda x: x in word, patterns)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        count = 0\n",
    "\n",
    "        for pattern in patterns:\n",
    "            if pattern in word:\n",
    "                count += 1\n",
    "\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        cnt = 0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return sum([1 if _ in word else 0 for _ in patterns])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return sum(i in word for i in patterns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return len([i for i in patterns if word.find(i)!= -1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        cnt = 0\n",
    "        for s in patterns:\n",
    "            if s in word:\n",
    "                cnt+=1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return sum(1 for p in patterns if p in word)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        cnt = 0\n",
    "        for item in patterns:\n",
    "            if item in word:\n",
    "                cnt = cnt + 1\n",
    "        return cnt "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        ans = 0\n",
    "        for w in patterns:\n",
    "            if w in word:\n",
    "                ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return sum(1 for s in patterns if s in word)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        res = 0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                res += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        ans = 0\n",
    "        for pattern in patterns:\n",
    "            if pattern in word:\n",
    "                ans += 1\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        num = 0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                num += 1\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        cnt = 0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                cnt += 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "#         return len(list(filter(lambda x: x in word, patterns)))\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        def check(pattern: str, word: str) -> bool:\n",
    "            m = len(pattern)\n",
    "            n = len(word)\n",
    "            # 生成 pattern 的前缀数组\n",
    "            pi = [0] * m\n",
    "            j = 0\n",
    "            for i in range(1, m):\n",
    "                while j and pattern[i] != pattern[j]:\n",
    "                    j = pi[j - 1]\n",
    "                if pattern[i] == pattern[j]:\n",
    "                    j += 1\n",
    "                pi[i] = j\n",
    "            # 利用前缀数组进行匹配 \n",
    "            j = 0\n",
    "            for i in range(n):\n",
    "                while j and word[i] != pattern[j]:\n",
    "                    j = pi[j - 1]\n",
    "                if word[i] == pattern[j]:\n",
    "                    j += 1\n",
    "                if j == m:\n",
    "                    return True\n",
    "            return False\n",
    "        \n",
    "        res = 0\n",
    "        for pattern in patterns:\n",
    "            res += check(pattern, word)\n",
    "        return res\n",
    "\n",
    "# 作者：力扣官方题解\n",
    "# 链接：https://leetcode.cn/problems/number-of-strings-that-appear-as-substrings-in-word/solutions/936704/zuo-wei-zi-zi-fu-chuan-chu-xian-zai-dan-wmsp4/\n",
    "# 来源：力扣（LeetCode）\n",
    "# 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "\n",
    "        cnt = 0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                cnt += 1\n",
    "        \n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return sum(i in word for i in patterns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return sum(x in word for x in patterns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        ans=0\n",
    "        for s in patterns:\n",
    "            if s in word:\n",
    "                ans+=1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        count=0\n",
    "        for i in patterns:\n",
    "            if i in word:\n",
    "                count+=1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        return len(list(filter(lambda x: x in word, patterns)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "#         return len(list(filter(lambda x: x in word, patterns)))\n",
    "\n",
    "class Solution:\n",
    "    def numOfStrings(self, patterns: List[str], word: str) -> int:\n",
    "        def check(pattern: str, word: str) -> bool:\n",
    "            m = len(pattern)\n",
    "            n = len(word)\n",
    "            # 生成 pattern 的前缀数组\n",
    "            pi = [0] * m\n",
    "            j = 0\n",
    "            for i in range(1, m):\n",
    "                while j and pattern[i] != pattern[j]:\n",
    "                    j = pi[j - 1]\n",
    "                if pattern[i] == pattern[j]:\n",
    "                    j += 1\n",
    "                pi[i] = j\n",
    "            # 利用前缀数组进行匹配 \n",
    "            j = 0\n",
    "            for i in range(n):\n",
    "                while j and word[i] != pattern[j]:\n",
    "                    j = pi[j - 1]\n",
    "                if word[i] == pattern[j]:\n",
    "                    j += 1\n",
    "                if j == m:\n",
    "                    return True\n",
    "            return False\n",
    "        \n",
    "        res = 0\n",
    "        for pattern in patterns:\n",
    "            res += check(pattern, word)\n",
    "        return res\n",
    "\n",
    "# 作者：力扣官方题解\n",
    "# 链接：https://leetcode.cn/problems/number-of-strings-that-appear-as-substrings-in-word/solutions/936704/zuo-wei-zi-zi-fu-chuan-chu-xian-zai-dan-wmsp4/\n",
    "# 来源：力扣（LeetCode）\n",
    "# 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
